#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unistd.h>
#include <functional>

// c++11包装器 using func = std::function<void()>;
typedef std::function<void()> func; 

std::vector<func> cmdSet;  //指令集 存储指令函数
std::unordered_map<int, std::string> cmdContent; //指令内容 指令Id:指令信息

void accessSQL()
{
    std::cout << "sub process[" << getpid() << "] 正在执行访问数据库的任务..." << std::endl
              << std::endl;
}

void AnalyzeUrl()
{
    std::cout << "sub process[" << getpid() << "] 正在执行解析网址任务..." << std::endl
              << std::endl;
}

void calResult()
{
    std::cout << "sub process[" << getpid() << "] 正在执行计算结果任务..." << std::endl
              << std::endl;
}

void saveData()
{
    std::cout << "sub process[" << getpid() << "] 正在执行保存数据任务..." << std::endl
              << std::endl;
}

void Load()
{
    size_t cmdId = 0;

    cmdContent.insert({cmdId++, "accessSQL: 访问数据库"});
    cmdSet.push_back(accessSQL);

    cmdContent.insert({cmdId++, "AnalyzeUrl: 解析网址"});
    cmdSet.push_back(AnalyzeUrl);

    cmdContent.insert({cmdId++, "calResult: 计算结果"});
    cmdSet.push_back(calResult);

    cmdContent.insert({cmdId, "saveData: 保存数据"});
    cmdSet.push_back(saveData);
}

void showCmdset()
{ 
    for (const auto &cmd : cmdContent)
    {
        std::cout << cmd.first << "\t" << cmd.second << std::endl;
    }
}

int cmdSetsize()
{
    return cmdSet.size();
}